package com.kuangjia.student_ems.dto;

import com.kuangjia.student_ems.entity.Leave;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LeaveDTO {
    
    private Long id;
    private Long userId;
    private String userName;
    private Long departmentId;
    private String departmentName;
    private Leave.LeaveType type;
    private String typeDesc;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private String reason;
    private Leave.LeaveStatus status;
    private String statusDesc;
    private String rejectReason;
    private String approveReason;
    private Long approverId;
    private String approverName;
    private LocalDateTime approveTime;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    public static LeaveDTO fromEntity(Leave leave) {
        LeaveDTO dto = new LeaveDTO();
        dto.setId(leave.getId());
        dto.setUserId(leave.getUser().getId());
        dto.setUserName(leave.getUser().getName());
        if (leave.getUser().getDepartment() != null) {
            dto.setDepartmentId(leave.getUser().getDepartment().getId());
            dto.setDepartmentName(leave.getUser().getDepartment().getName());
        }
        dto.setType(leave.getType());
        dto.setStartTime(leave.getStartTime());
        dto.setEndTime(leave.getEndTime());
        dto.setReason(leave.getReason());
        dto.setStatus(leave.getStatus());
        dto.setRejectReason(leave.getRejectReason());
        dto.setApproveReason(leave.getApproveReason());
        dto.setCreateTime(leave.getCreateTime());
        dto.setUpdateTime(leave.getUpdateTime());
        
        if (leave.getApprover() != null) {
            dto.setApproverId(leave.getApprover().getId());
            dto.setApproverName(leave.getApprover().getName());
            dto.setApproveTime(leave.getApproveTime());
        }
        
        return dto;
    }
} 